package test3;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class TestPTPConsumerAsyn {
	public static void main(String[] args) throws JMSException {
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://10.222.29.178:61616");
		Destination queue = new ActiveMQQueue("jason");
		Connection con = factory.createConnection();
		con.start();
		
		final Session session = con.createSession(true, Session.AUTO_ACKNOWLEDGE);
		final MessageConsumer consumer = session.createConsumer(queue);
		
//		new Thread(){
//			public void run() {
//				while(true){
//					TextMessage msg1;
//					TextMessage msg2;
//					try {
//						msg1 = (TextMessage) consumer.receive();
//						System.out.println(msg1.getText());
//						msg2 = (TextMessage) consumer.receive();
//						System.out.println(msg2.getText());
//					} catch (JMSException e) {
//						// TODO Auto-generated catch block
//						e.printStackTrace();
//					}
//				}
//			};
//		}.start();
		
		
		consumer.setMessageListener(new MessageListener() {
			@Override
			public void onMessage(Message arg0) {
				TextMessage msg2 = (TextMessage) arg0;
				
				// TODO Auto-generated method stub
				try {
//					session.commit();
					System.out.println(msg2.getText());
				} catch (JMSException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		
		
//		consumer.close();
//		session.close();
//		con.close();
	}
}
